/* 2017-10-26 11:30:57 | 修改 木遥（微信:  http://marsgis.cn/weixin.html ） */
//模块：
mars3d.widget.bindClass(mars3d.widget.BaseWidget.extend({
    options: {
        //弹窗
        view: {
            type: "append",
            url: "view.html",
        }
    },
    //初始化[仅执行1次]
    create: function() {
        var index = 0;
        var basemapsCfg = this.getBasemaps();
        for (var i = 0; i < basemapsCfg.length; i++) {
            var item = basemapsCfg[i];
            if (!item.hasLayer || item.hide) continue;
            index++;
        }

        if (index <= 4) {
            this.options.view.windowOptions = {
                width: 190,
                height: Math.ceil(index / 2) * 100 + 70
            }
        } else if (index > 4 && index <= 6) {
            this.options.view.windowOptions = {
                width: 270,
                height: Math.ceil(index / 3) * 100 + 70
            }
        } else {
            this.options.view.windowOptions = {
                width: 360,
                height: Math.ceil(index / 4) * 105 + 70
            }
        }


    },
    viewWindow: null,
    handler: null,
    qingxielayer: null,
    mousemove: function() {

    },
    //每个窗口创建完成后调用
    winCreateOK: function(opt, result) {
        this.viewWindow = result;
    },
    //打开激活
    activate: function() {
        this.dealQingxie();
    },
    //关闭释放
    disable: function() {
        this.removeQinxie();
    },
    // 创建切斜摄影
    dealQingxie: function() {
        viewer.mars.updateTerrainProvider(false);
        //start
        //start
        //url: "http://10.190.54.56:7763/TILE_3D_MODEL/futian_v1/tileset.json",
        const mapurl = new Cesium.Resource({
            url: "http://10.190.54.56:7763/TILE_3D_MODEL/futian/tileset.json",
            headers: { "szvsud-license-key": "eTG1UGBSvr4HdQnLecWX1s8GA4NWjLe8Rp8eI9ztla05D5mPYyi3rvVRX0RGjm5G" }
        });
         this.qingxielayer = new Cesium.Cesium3DTileset({
            url: mapurl, // 你的倾斜摄影服务发布地址  // "http://localhost/xmhtileset/tileset.json",
            skipLevelOfDetail: true,
            preferLeaves: true,
            maximumScreenSpaceError: 16,
            skipLevels: 1,
        });
        this.qingxielayer.readyPromise.then(tileSet => {
            viewer.scene.primitives.add(tileSet); // 将倾斜摄影实体加载到地图上

            viewer.zoomTo(tileSet);
        });
        viewer.showtileset = true;
        this.lmap = this.viewer.mars.getBasemap();
    },
    //将3d模型删除
    removeQinxie: function() {
        viewer.mars.updateTerrainProvider(true);
        viewer.scene.primitives.remove(this.qingxielayer); //销毁
        viewer.showtileset = false;
        // qingxiemaplayer && qingxiemaplayer.setVisible(true);
    },
    lmap: null,
    handlerTimer: null,
    //显示地形
    hasTerrain: function() {
        return this.viewer.mars.hasTerrain();
    },
    //获取底图
    getBasemaps: function() {
        return this.viewer.mars.config.basemaps;
    },
    getLayerVisible: function(item) {
        var model = this.viewer.mars.getLayer(item);
        return model && model.getVisible();
    },
    updateLayerVisible: function(item, visible) {
        var model = this.viewer.mars.getLayer(item);
        model && model.setVisible(visible);
    },
    updateTerrainVisible: function(isStkTerrain) {
        this.viewer.mars.updateTerrainProvider(isStkTerrain);
    },
    // 改变初始视角
    changeBaseAngle: function() {
        this.viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(114.036922, 22.532865, 13844.77),
            orientation: {
                heading: Cesium.Math.toRadians(358.0),
                pitch: Cesium.Math.toRadians(-90.0),
                roll: Cesium.Math.toRadians(0.0)
            }
        })
    }
}));